package cn.itsource.exam.controller;

import cn.itsource.exam.domain.SubjectInfo;
import cn.itsource.exam.domain.StudentInfo;
import cn.itsource.exam.query.SubjectQuery;
import cn.itsource.exam.service.SubjectService;
import cn.itsource.exam.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by su on 2020/7/8.
 */
@RestController
@RequestMapping("/subject")
public class SubjectController {

    @Autowired
    private SubjectService subjectService;


    /**
     * 增加或修改班级
     * @param paramIn
     */
    @RequestMapping(value = "modify",method = RequestMethod.POST)
    public  String modifySubject(@RequestBody SubjectInfo paramIn, HttpServletRequest rq){
        StudentInfo info = (StudentInfo)rq.getSession().getAttribute(rq.getHeader("U-TOKEN"));
        return subjectService.modifySubject(paramIn, info.getName());
    }

    /**
     * 刪除班级
     * @param id
     */
    @RequestMapping(value = "del",method = RequestMethod.POST)
    public String delSubject(Long id, HttpServletRequest rq){
        StudentInfo info = (StudentInfo)rq.getSession().getAttribute(rq.getHeader("U-TOKEN"));
        return subjectService.delSubject(id, info.getName());
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @RequestMapping(value = "batchdel",method = RequestMethod.POST)
    public String batchDelUser(String ids, HttpServletRequest rq){
        StudentInfo info = (StudentInfo)rq.getSession().getAttribute(rq.getHeader("U-TOKEN"));
        return subjectService.batchDelSubject(ids, info.getName());
    }

    /**
     * 根据主键获取学科
     * @param id
     * @return
     */
    @RequestMapping(value = "get",method = RequestMethod.GET)
    public SubjectInfo getSubjectById(Long id){
        return subjectService.getSubjectById(id);
    }

    /**
     * 分页查询学科
     * @param paramIn
     * @return
     */
    @PostMapping("listpage")
    public PageList<SubjectInfo> getSubjectListPage(@RequestBody SubjectQuery paramIn){
        return subjectService.getSubjectListPage(paramIn);
    }

    /**
     * 查询所有学科
     * @return
     */
    @PostMapping("list")
    public List<SubjectInfo> getSubjectList(){
        return subjectService.getSubjectList();
    }
}
